const express = require('express')

const app = express()

app.use('*', (req, res, next) => {
	res.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1:5605')
	res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PATCH,DELETE,PUT')
	res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
	next()
})

app.post('/info', function (req, res) {
	// TODO 4 - 暴露可获取自定义响应头,可以写在上面，不过这种一般写在特定接口
	res.set('dh', '29')
	res.set('dxy', '2')
	res.setHeader('Access-Control-Expose-Headers', 'dh,dxy')

	res.json({
		code: 200,
		type: 'post',
	})
})

app.listen(8000, () => {
	console.log('http://localhost:8000')
})
